package com.atguigu.lease.web.admin.controller.system;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.SystemPost;
import com.atguigu.lease.model.enums.BaseStatus;
import com.atguigu.lease.web.admin.service.SystemPostService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Package: com.atguigu.lease.web.admin.controller.system
 *
 * @Description:
 * @Author xiongkunYang
 * @Create 2025/4/19 23:06
 */
@RestController
@Tag(name = "后台用户岗位管理")
@RequestMapping("/admin/system/post")
public class SystemPostController {

    private final SystemPostService systemPostService;

    public SystemPostController(SystemPostService systemPostService) {
        this.systemPostService = systemPostService;
    }

    @Operation(summary = "分页获取岗位信息")
    @GetMapping("page")
    private Result<IPage<SystemPost>> page(@RequestParam long current, @RequestParam long size) {
        return Result.ok(this.systemPostService.page(new Page<>(current, size)));
    }

    @Operation(summary = "保存或更新岗位信息")
    @PostMapping("saveOrUpdate")
    public Result<Boolean> saveOrUpdate(@RequestBody SystemPost systemPost) {
        return Result.ok(this.systemPostService.saveOrUpdate(systemPost));
    }

    @DeleteMapping("deleteById")
    @Operation(summary = "根据id删除岗位")
    public Result<Boolean> removeById(@RequestParam Long id) {
        return Result.ok(this.systemPostService.removeById(id));
    }

    @GetMapping("getById")
    @Operation(summary = "根据id获取岗位信息")
    public Result<SystemPost> getById(@RequestParam Long id) {
        return Result.ok(this.systemPostService.getById(id));
    }

    @Operation(summary = "获取全部岗位列表")
    @GetMapping("list")
    public Result<List<SystemPost>> list() {
        return Result.ok(this.systemPostService.list());
    }

    @Operation(summary = "根据岗位id修改状态")
    @PostMapping("updateStatusByPostId")
    public Result<Boolean> updateStatusByPostId(@RequestParam Long id, @RequestParam BaseStatus status) {
        return Result.ok(this.systemPostService
                .update(new LambdaUpdateWrapper<SystemPost>()
                        .eq(SystemPost::getId, id)
                        .set(SystemPost::getStatus, status)));
    }
}
